#!C:\Python\Python36\Python.exe
# -*- coding:utf-8 -*-
#@Time  : 2020-01-13 15:58
#@Author: iceman
#@File  : test01case.py
"""读取userCase.xlsx中的用例，使用unittest来进行断言校验"""
import json
import urllib
from urllib import parse
import geturlParams
import readExcel
import unittest

from common import configHttp

class testUserLogin(unittest.TestCase):
    """测试登录接口"""
    def test01case(self):
        """读取excel用例表格中请求参数"""
        self.method = readExcel.readExcel(2, 'D').get_xls()
        self.case_name = readExcel.readExcel(2, 'A').get_xls()
        self.data = readExcel.readExcel(2, 'C').get_xls()
        self.url = geturlParams.geturlParams().get_Url()
        self.checkresult()

    def checkresult(self):
        data = dict(urllib.parse.parse_qsl(self.data))
        info = configHttp.RunMain().run_main(self.method, self.url, data)
        # 将 str 对象转换为 Python 字典
        data_dict = json.loads(info)
        if self.case_name == 'login':
            self.assertEqual(data_dict['code'], 200)
        if self.case_name == 'login_error':
            self.assertEqual(data_dict['code'], -1)
        if self.case_name == 'login_null':
            self.assertEqual(data_dict['code'], 10001)

if __name__ == '__main__':
    testUserLogin().test01case()